package br.com.j7.jdesk.persistence.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

/**
 * <b>J7system</b>
 * 
 * 
 * @author Edivando Alves
 *
 */
@Entity
public class Sales implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer idSale;
	
	@OneToMany(mappedBy="sale", cascade=CascadeType.MERGE)
	private List<ProductsSales> productsSales;
	
	@ManyToOne
	@JoinColumn(name="idCustomer")
	private Customers customer;
	
	@ManyToOne
	@JoinColumn(name="idUser")
	private Users user;
	
	@ManyToOne
	@JoinColumn(name="idEnterprise")
	private Enterprises enterprise;
	
	private Double nrTotalSale;
	
	private String cdPayment;
	
	@Version
	@Temporal(TemporalType.TIMESTAMP)
	private Date dtSale;

	public Integer getIdSale() {
		return idSale;
	}

	public void setIdSale(Integer idSale) {
		this.idSale = idSale;
	}

	public List<ProductsSales> getProductsSales() {
		return productsSales;
	}

	public void setProductsSales(List<ProductsSales> productsSales) {
		this.productsSales = productsSales;
	}

	public Customers getCustomer() {
		return customer;
	}

	public void setCustomer(Customers customer) {
		this.customer = customer;
	}

	public Users getUser() {
		return user;
	}

	public void setUser(Users user) {
		this.user = user;
	}

	public Enterprises getEnterprise() {
		return enterprise;
	}
	
	public void setEnterprise(Enterprises enterprise) {
		this.enterprise = enterprise;
	}
	
	public Double getNrTotalSale() {
		return nrTotalSale;
	}

	public void setNrTotalSale(Double nrTotalSale) {
		this.nrTotalSale = nrTotalSale;
	}

	public String getCdPayment() {
		return cdPayment;
	}

	public void setCdPayment(String cdPayment) {
		this.cdPayment = cdPayment;
	}

	public Date getDtSale() {
		return dtSale;
	}

	public void setDtSale(Date dtSale) {
		this.dtSale = dtSale;
	}

	@Override
	public int hashCode() {
		return idSale;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Sales other = (Sales) obj;
		if (idSale == null) {
			if (other.idSale != null)
				return false;
		} else if (!idSale.equals(other.idSale))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return idSale.toString();
	}

}
